<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/resources/layout/templateInterno.xhtml"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:rich="http://richfaces.org/rich">
    
    
	<ui:define name="body">
	
	
	<div class="grid-11-12">
		<h:panelGroup id="exibirTitulo">
			<h:panelGroup rendered="#{visitanteCadastro.acaoTela != ''}">
				
					<h1>#{visitanteCadastro.acaoTela} VISITANTE</h1>
				
			</h:panelGroup>
			<h:panelGroup rendered="#{visitanteCadastro.acaoTela == ''}">
				<div class="grid-11-12">
					<h1>PESQUISAR VISITANTE</h1>
				</div>
			</h:panelGroup>
		</h:panelGroup>
	</div>
	<div class="field-clear"></div>
		<div style="padding-bottom: 10px;" class="form">
		<h:form id="formCadastroVisitante"  style="width:100%">
		<h:panelGroup id="pgMensagens">
			  <div>
					<h:messages style="padding:5px" errorClass="errorMessage" infoClass="infoMessage"  />
			</div>
		</h:panelGroup>
		<div class="field-clear"></div>
		<h:panelGroup rendered="#{visitanteCadastro.exibirCadastro}" id="pgDadosPessoais">
		
			<t:fieldset id="idfsDadosPessoais" style="width:750px"  legend="Dados">
					
					<div class="grid-5-12">
						<em class="form-req">*</em>
						<h:outputLabel  id="lbNome" class="form-lbl"  value="Nome:"/>
						<h:inputText maxlength="100"  required="true" label="Nome" id="inptNome" styleClass="form-txt"  value="#{visitanteCadastro.visitante.nome}" />
					</div>
					<div class="grid-2-12">
						<em class="form-req">*</em>
						<h:outputLabel  id="lbSexo" class="form-lbl"  value="Sexo:"/>
						<h:selectOneMenu  required="true" label="Sexo" id="cbSexo" styleClass="form-txt" value="#{visitanteCadastro.visitante.sexo}">
					 		<f:selectItem itemLabel="Selecione ..." itemValue=""/>
					 		<f:selectItem itemLabel="Masculino" itemValue="M"/>
					 		<f:selectItem itemLabel="Feminino" itemValue="F"/>
				 		</h:selectOneMenu>
					</div>
					<div class="grid-2-12">
						<h:outputLabel  id="lbEstadoCivil" class="form-lbl"  value="Estado Civil:"/>
						<h:selectOneMenu id="cbEstadoCivil"  styleClass="form-select" value="#{visitanteCadastro.visitante.estadoCivil}">
							<f:selectItem itemLabel="Selecione ..." itemValue=""/>
					 		<f:selectItem itemLabel="Casado(a) " itemValue="CS"/>
					 		<f:selectItem itemLabel="Separado(a) " itemValue="SP"/>
					 		<f:selectItem itemLabel="Solteiro(a) " itemValue="ST"/>
				 			<f:selectItem itemLabel="Divorciado(a) " itemValue="DV"/>
			 				<f:selectItem itemLabel="Viúvo(a) " itemValue="VU"/>
			 				
				 		</h:selectOneMenu>
					</div>
					<div class="field-clear"></div>
						 <div class="grid-4-12">
						<h:outputLabel  id="lbLogradouro" class="form-lbl"  value="Logradouro:"/>
						<h:inputText  id="inptLogradouro" maxlength="100" styleClass="form-txt" value="#{visitanteCadastro.visitante.logradouro}" />
					</div>
					<div class="grid-1-12">
						<h:outputLabel  id="lbNumero" class="form-lbl"  value="Número:"/>
						<h:inputText  id="inptNumero" maxlength="10" styleClass="form-txt" value="#{visitanteCadastro.visitante.numero}" >
							 <rich:jQuery selector="#inptNumero" query="mask('?99999')" timing="onload"/>
						</h:inputText>
					</div>
					<div class="grid-3-12">
						<h:outputLabel  id="lbComplemento" class="form-lbl"  value="Complemento:"/>
						<h:inputText  id="inptComplemento" maxlength="100" styleClass="form-txt" value="#{visitanteCadastro.visitante.complemento}" />
					</div>
					<div class="grid-3-12">
						<h:outputLabel  id="lbBairro" class="form-lbl"  value="Bairro:"/>
						<h:inputText  id="inptBairro" maxlength="100" styleClass="form-txt" value="#{visitanteCadastro.visitante.bairro}" />
					</div>
					<div class="grid-2-12">
						<h:outputLabel  id="lbCep" class="form-lbl"  value="CEP"/>
						<h:inputText  id="inptCep" maxlength="25" styleClass="form-txt" value="#{visitanteCadastro.visitante.cep}" >
							 <rich:jQuery selector="#inptCep" query="mask('99999-999')" timing="onload"/>
						</h:inputText>
					</div>
					<div class="grid-4-12">
						<h:outputLabel  id="lbCidade" class="form-lbl"  value="Cidade:"/>
						<h:inputText  id="inptCidade" maxlength="100" styleClass="form-txt" value="#{visitanteCadastro.visitante.cidade}" />
					</div>	
					<div class="grid-2-12">
							<h:outputLabel  id="lbTelefone" class="form-lbl"  value="Telefone:"/>
							<h:inputText  id="inptTelefone" styleClass="form-txt" value="#{visitanteCadastro.visitante.telefone}" >	
								 <rich:jQuery selector="#inptTelefone" query="mask('(99) 9999-9999')" timing="onload"/>				
							 </h:inputText>
						</div>
				
					<div class="grid-2-12">
							<h:outputLabel  id="lbCelular" class="form-lbl"  value="Celular:"/>
							<h:inputText  id="inptCelular" styleClass="form-txt" value="#{visitanteCadastro.visitante.celular}" >
									 <rich:jQuery selector="#inptCelular" query="mask('(99) 9999-9999')" timing="onload"/>	
							</h:inputText>					
						</div>
					
					<div class="grid-4-12">
							<h:outputLabel  id="lbLocalPertence"  class="form-lbl"  value="Igreja:"/>
						<h:selectOneMenu converter="indexConverter" defaultLabel="Selecione..." width="200"   
							 required="true" label="Igreja"
						id="cbLocalFrequencia"  value="#{visitanteCadastro.visitante.igrejaPertence}">
						<f:selectItem itemLabel="Selecione..." itemValue=""/>
							   <t:selectItems value="#{visitanteCadastro.listaIgreja}" var="igreja" itemLabel="#{igreja.nome}" itemValue="#{igreja}"/>
						</h:selectOneMenu>
					</div>
						<div class="grid-3-12">
							<h:outputLabel  id="lbDataNascimento" class="form-lbl"  value="Dat. Nascimento:"/>
							<rich:calendar  id="clDataNascimento" firstWeekDay="0"
											value="#{visitanteCadastro.visitante.dtNascimento}" 
											datePattern="dd/MM/yyyy" 
											converterMessage="#{msg['erro.MSG_06']}"
											inputSize="10" 
											showWeeksBar="false"
											inputClass="maskDate"
											enableManualInput="true" 
											disabled="false">
							</rich:calendar>
							<rich:jQuery id="mskDataNascimento" selector=".maskDate" timing="onload" query="mask('99/99/9999',{placeholder:' '})" /> 	
						</div>	
						<div class="field-clear"></div>
						<div class="grid-3-12">
							<em class="form-req">*</em>
							<h:outputLabel  id="lbDataCadastro" class="form-lbl"  value="Dat. Cadastro:"/>
							<rich:calendar required="true" label="Dat. Cadastro"  id="clDataCadastro" firstWeekDay="0" minDaysInFirstWeek="2"
											value="#{visitanteCadastro.visitante.dtCadastroVisitante}" 
											datePattern="dd/MM/yyyy"
											converterMessage="#{msg['erro.MSG_06']}" 
											inputSize="10" showWeeksBar="false"
											inputClass="maskDate"
											enableManualInput="true" 
											disabled="false">
							</rich:calendar>
							<rich:jQuery id="mskDateCadastroMembro" selector=".maskDate" timing="onload" query="mask('99/99/9999',{placeholder:' '})" /> 	
						</div>	
					<a4j:region>
					<div class="grid-5-12">
					<h:outputLabel  id="lbMembroResponsavel" class="form-lbl"  value="Responsável:"/>
					 <h:inputText styleClass="form-txt"  value="#{visitanteCadastro.membro}" id="text" >
					 </h:inputText>
								<rich:suggestionbox styleClass="form-txt"  ajaxSingle="true" id="suggestionBoxId"
									for="text" suggestionAction="#{visitanteCadastro.autocomplete}"
									var="membro" fetchValue="#{membro.label}"
									rows="#{suggestionBox.intRows}"
									nothingLabel="Nenhum membro encontrado." columnClasses="center"
									usingSuggestObjects="true">
	
									<h:column>
										<h:outputText value="#{membro.label}" />
									</h:column>
	
									<a4j:support event="onselect">
										<f:setPropertyActionListener value="#{membro.value}" target="#{visitanteCadastro.coMembro}" />
									</a4j:support>
								</rich:suggestionbox>
	
							</div>	
					</a4j:region>
					<div class="field-clear"></div>
					<div class="grid-4-12">
						<h:outputLabel  id="lbEmail" class="form-lbl"  value="Email:"/>
						<h:inputText maxlength="100" style="text-transform: lowercase;" id="inptEmail" styleClass="form-txt" value="#{visitanteCadastro.visitante.email}" />					
					</div>
					<h:panelGroup id="pgVisitanteInativar" rendered="#{visitanteCadastro.visitante.coSeqVisitante != null}" >
						<div class="grid-2-12" >
				  			 <h:outputLabel  id="lbInativar" class="form-lbl"  value="Inativar Regitro?"/>
							 <h:selectBooleanCheckbox  id="checkStCadastro"  styleClass="form-txt" value="#{visitanteCadastro.visitante.inativo}" >	
								 <a4j:support id="sptStatus"  ajaxSingle="true" event="onclick"  ></a4j:support>						
							 </h:selectBooleanCheckbox>
						</div>	
					</h:panelGroup>		
					<div  class="field-clear"> </div>
					<div class="grid-7-12">
						<h:outputLabel id="lbDescricao" class="form-lbl" value="Observação:" />
							 <h:inputTextarea  onkeyup="this.value = this.value.substring(0, 2000);" id="observacao" style="width: 700px; height: 100px"  styleClass="form-txt" value="#{visitanteCadastro.visitante.observacao}" >
							 </h:inputTextarea>
						</div>							
			 </t:fieldset>
		 </h:panelGroup>
		 <div  class="field-clear"> </div>
		 <h:panelGroup id="pgBotaoVoltar" rendered="#{visitanteCadastro.exibirBotaoVoltar}">
				 <div  class="grid-2-12">
						<a4j:commandButton  styleClass="form-button" immediate="true" id="cbVoltar" value="Voltar" reRender="formCadastroVisitante,exibirTitulo" action="#{visitanteCadastro.voltar}" >	</a4j:commandButton>
				</div >
			</h:panelGroup>
		 <h:panelGroup  rendered="#{usuarioLogado.exibirSalvar}">
		 	<h:panelGroup id="pgBotaoSalvar" rendered="#{visitanteCadastro.exibirBotaoSalvar}">
				 <div  class="grid-2-12">
						<a4j:commandButton styleClass="form-button" id="cbSalvar" value="Salvar" reRender="formCadastroVisitante,pgMensagens" action="#{visitanteCadastro.salvar}" >	</a4j:commandButton>
				</div >
			</h:panelGroup>
		</h:panelGroup>
		<h:panelGroup  rendered="#{usuarioLogado.exibirEditar}">
			<h:panelGroup id="pgBotaoAtualizar" rendered="#{visitanteCadastro.exibirBotaoAtualizar}">
				 <div  class="grid-2-12">
						<a4j:commandButton  styleClass="form-button" id="cbAtualizar" value="Atualizar" reRender="formCadastroVisitante" action="#{visitanteCadastro.salvar}" >	</a4j:commandButton>
				</div >
			</h:panelGroup>
		</h:panelGroup>
			
				<h:panelGroup  rendered="#{usuarioLogado.exibirExcluir}">
					<h:panelGroup id="pgBotaoExcluir" rendered="#{visitanteCadastro.exibirBotaoExcluir}">
					 <div class="grid-2-12">
							<a4j:commandButton onclick="Richfaces.showModalPanel('modalPanelConfirmaExcluir');" styleClass="form-button" id="cbExcluir" value="Excluir" reRender="formCadastroVisitante" >	</a4j:commandButton>
					</div >
				</h:panelGroup>
			</h:panelGroup>
			<h:panelGroup  rendered="#{usuarioLogado.exibirEditar}">
				<h:panelGroup id="pgBotaoTornarMembro" rendered="#{visitanteCadastro.exibirBotaoAtualizar}">
					<h:panelGroup id="pgBotaoTornarMembroStatus" rendered="#{visitanteCadastro.visitante.inativo == false}">
						 <div  class="grid-2-12">
							<a4j:commandButton  styleClass="form-button"  onclick="Richfaces.showModalPanel('modalPanelConfirmaTornarMembro');" id="cbTornarMembro" value="Tornar Membro"  >	
								<f:setPropertyActionListener target="#{baseView.listaResult}" value="#{visitanteCadastro.listaVisitante}"/>
							</a4j:commandButton>
						</div >
					</h:panelGroup>
				</h:panelGroup>
			</h:panelGroup>
		<div class="field-clear"></div>
		
		<h:panelGroup id="pgFiltroPesquisa" rendered="#{visitanteCadastro.exibirPesquisa}" >
			
			<div class="field-clear"></div>
			 <t:fieldset id="idfsDadosPesquisa" rendered="#{visitanteCadastro.exibirPesquisa}" style="width: 800px; float: left" legend="Filtros">
			 	 <div class="grid-5-12">
						<h:outputLabel class="form-lbl"  value="Nome:"/>				
						<h:inputText styleClass="form-txt"  value="#{visitanteCadastro.visitantePesquisa.nome}" id="nomePesquisa" />
				</div>
				<div class="grid-3-12">
							<h:outputLabel  id="lbDataNascimentoPesquisa" class="form-lbl"  value="Dat. Nascimento:"/>
							<rich:calendar   id="clDataNascimentoPesquisa" firstWeekDay="0" minDaysInFirstWeek="2"
											value="#{visitanteCadastro.visitantePesquisa.dtNascimento}" 
											datePattern="dd/MM/yyyy" 
											inputSize="10" 
											showWeeksBar="false"
											converterMessage="#{msg['erro.MSG_06']}"
											inputClass="maskDate"
											enableManualInput="true" 
											disabled="false">
							</rich:calendar>
							<rich:jQuery id="mskDataNascimentoPesquisa" selector=".maskDate" timing="onload" query="mask('99/99/9999',{placeholder:' '})" /> 	
						</div>	
					<h:panelGroup id="pgIgrejaPertence" >
						<div class="grid-4-12">
							<h:outputLabel  id="lbLocalPertencePesquisa"  class="form-lbl"  value="Igreja:"/>
							<h:selectOneMenu converter="indexConverter"  id="cbLocalFrequenciaPesquisa"  value="#{visitanteCadastro.visitantePesquisa.igrejaPertence}">
							 		<f:selectItem itemLabel="Selecione..." itemValue=""/>
								   <t:selectItems value="#{visitanteCadastro.listaIgreja}" var="igreja" itemLabel="#{igreja.nome}" itemValue="#{igreja}"/>
							</h:selectOneMenu>
						</div>
					</h:panelGroup>	
					<div class="field-clear"></div>
					<div class="grid-2-12">
						<h:outputLabel  id="lbStatus" class="form-lbl"  value="Status:"/>
						<h:selectOneMenu id="cbStatusPesquisa" styleClass="form-txt" value="#{visitanteCadastro.status}">
					 		<f:selectItem itemLabel="Todos" itemValue=""/>
					 		<f:selectItem itemLabel="Ativo" itemValue="A"/>
					 		<f:selectItem itemLabel="Inativo" itemValue="I"/>
				 		</h:selectOneMenu>
				</div>
			</t:fieldset>
			<div class="field-clear"></div>
		 		<div class="grid-2-12">
					<a4j:commandButton id="cbPesquisar" process="idfsDadosPesquisa" ajaxSingle="true"  styleClass="form-button" action="#{visitanteCadastro.pesquisar}" reRender="pgVisitanteTabela,pgResultadoas,pgMensagens" value="Pesquisar" >
					</a4j:commandButton>
				</div>
				<h:panelGroup  rendered="#{usuarioLogado.exibirNovo}">
					<div class="grid-2-12">
							<a4j:commandButton  styleClass="form-button" id="cbNovo" value="Novo" reRender="formCadastroVisitante,exibirTitulo" action="#{visitanteCadastro.novo}" >	</a4j:commandButton>
					</div>
				</h:panelGroup>
			 <div class="field-clear"></div>
			 <div  >
			 <h:panelGroup id="pgVisitanteTabela">
				 <rich:dataTable  rendered="#{not empty visitanteCadastro.listaVisitante}"
	                    			     rowClasses="odd, even" rows="10"
	                    			styleClass="dataTable rich-table rich-table-cell ui-widget-content ui-grid-content"
	                    			width="750px" border="0" align="center" id="visitanteTable"  var="visitante" value="#{visitanteCadastro.listaVisitante}" >
					  <f:facet  name="header">
	                    <rich:columnGroup >
	                            <rich:column style="text-align: center; width:220px"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Nome" /></strong>
	                            </rich:column>
	                             <rich:column style="text-align: center;width:50px"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Dat. Nascimento" /></strong>
	                            </rich:column>
	                             <rich:column style="text-align: center; width:130px"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Igreja" /></strong>
	                            </rich:column>
	                             <rich:column style="text-align: center;width:15px"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Status" /></strong>
	                            </rich:column>
	                             <rich:column style="text-align: center; width:10px"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Ações" /></strong>
	                            </rich:column>
	                    	</rich:columnGroup>
	                  </f:facet>
	 				<rich:columnGroup >	
	 					<rich:column  style="text-align: left;" >
							<h:outputText value="#{visitante.nome}" />
						</rich:column>		
						 <rich:column style="text-align: center;" >
							<h:outputText value="#{visitante.dtNascimento}" />
						</rich:column>
						<rich:column  style="text-align: left;">
							<h:outputText value="#{visitante.igrejaPertence.nome}" />
						</rich:column>
						<rich:column  style="text-align: center;">
							<h:outputText value="#{visitante.status}" />
						</rich:column>
						<rich:column style="text-align: center;" >
						<h:panelGroup rendered="#{usuarioLogado.exibirEditar}">
							<a4j:commandLink id="editar" ajaxSingle="true" action="#{visitanteCadastro.editar}" reRender="formCadastroVisitante,exibirTitulo"  >
								<h:graphicImage value="/resources/imagens/ico_editar.gif" id="gIEdidar" styleClass="hidelink"/>
								 <f:setPropertyActionListener target="#{visitanteCadastro.visitante}" value="#{visitante}"/> 
							</a4j:commandLink>
						</h:panelGroup>
							<h:panelGroup rendered="#{usuarioLogado.exibirExcluir}">
								<a4j:commandLink id="remover" ajaxSingle="true" 
										onclick="Richfaces.showModalPanel('modalPanelConfirmaExcluir');"
										  >
									 <h:graphicImage value="/resources/imagens/ico_excluir.gif" id="gIExcluirUsers" styleClass="hidelink"/>
								   <f:setPropertyActionListener target="#{visitanteCadastro.visitante}" value="#{visitante}"/>
								</a4j:commandLink>
							</h:panelGroup>
						</rich:column>
					</rich:columnGroup>
				</rich:dataTable>
			</h:panelGroup>
			</div>
			<div class="grid-5-12" >
			<h:panelGroup id="pgResultadoas" style="padding-top:20px">
				<h:outputText styleClass="infoRegistroNaoEnc" value="#{msg['info.MGS_01']}" rendered="#{visitanteCadastro.registroNaoEncontrado}" />
			</h:panelGroup>
			</div>
			 <div class="field-clear"></div>
			<div class="grid-12-12">
				<rich:datascroller align="center" status="" renderIfSinglePage="false" for="visitanteTable" />
			</div>
		</h:panelGroup>
		</h:form>
		
		<rich:modalPanel id="modalPanelConfirmaExcluir" width="280"
					autosized="false" resizeable="false" height="110">
			<div class="form">
			<h:form id="fomModal" >
					<center>
						<div style="margin-left: 40px; margin-bottom: 30px" class="grid-9-12" >
							<h:outputText styleClass="infoRegistroNaoEnc" value="#{msg['info.MSG_02']}"  />
						</div>	
						 <div class="field-clear"></div>
						<div style="margin-left: 60px" class="grid-3-12" >
							<a4j:commandButton ajaxSingle="true" value="Confirmar" action="#{visitanteCadastro.excluir}" 
								id="btnConfirmar" styleClass="form-button"
								reRender="formCadastroVisitante,exibirTitulo" oncomplete="Richfaces.hideModalPanel('modalPanelConfirmaExcluir');"  style="width=50px">
							</a4j:commandButton>
						</div>	
						<div style="margin-left: 10px" class="grid-3-12" >
							<a4j:commandButton ajaxSingle="true" value="Cancelar" 				id="btnCancelar" styleClass="form-button"
								onclick="Richfaces.hideModalPanel('modalPanelConfirmaExcluir');"  style="width=50px">
							</a4j:commandButton>
						</div>	
					</center>
		</h:form>
		</div>
		</rich:modalPanel>
				
		<rich:modalPanel id="modalPanelConfirmaTornarMembro" width="400"
					autosized="false" resizeable="false" height="110">
			<div class="form">
			<h:form id="fomModalTornarMembro" >
					<center>
						<div style="margin-left: 40px; margin-bottom: 30px" class="grid-9-12" >
							<h:outputText styleClass="infoRegistroNaoEnc" value="Deseja tornar esse Visitante um Membro?"  />
						</div>	
						 <div class="field-clear"></div>
						<div style="margin-left: 60px" class="grid-3-12" >
							<a4j:commandButton ajaxSingle="true" value="Confirmar" action="#{membroCadastro.tornarMembro}" 
								id="btnConfirmarTornarMembro" styleClass="form-button"
								 oncomplete="Richfaces.hideModalPanel('modalPanelConfirmaTornarMembro');"  style="width=50px">
								  <f:setPropertyActionListener target="#{membroCadastro.visitante}" value="#{visitanteCadastro.visitante}"/>
							</a4j:commandButton>
						</div>	
						<div style="margin-left: 10px" class="grid-3-12" >
							<a4j:commandButton ajaxSingle="true" value="Cancelar" 				id="btnCancelarTornarMembro" styleClass="form-button"
								onclick="Richfaces.hideModalPanel('modalPanelConfirmaTornarMembro');"  style="width=50px">
							</a4j:commandButton>
						</div>	
					</center>
		</h:form>
		</div>
		</rich:modalPanel>
		
		</div>
		<t:saveState  value="#{visitanteCadastro.exibirCadastro}"/>
	   	<t:saveState  value="#{visitanteCadastro.exibirBotaoNovo}"/>	      
	    <t:saveState  value="#{visitanteCadastro.exibirBotaoAtualizar}"/>
	    <t:saveState  value="#{visitanteCadastro.exibirBotaoExcluir}"/>
	    <t:saveState  value="#{visitanteCadastro.exibirBotaoVoltar}"/>
		<t:saveState  value="#{visitanteCadastro.exibirBotaoSalvar}"/>
		<t:saveState  value="#{visitanteCadastro.exibirPesquisa}"/> 		
		<t:saveState  value="#{visitanteCadastro.visitantePesquisa}"/>
		<t:saveState  value="#{visitanteCadastro.coMembro}"/>
		<t:saveState  value="#{visitanteCadastro.visitante}"/>
		<t:saveState  value="#{visitanteCadastro.listaVisitante}"/>
		
		   
	</ui:define>
</ui:composition>

